<?php 
class Default_Bootstrap extends Zend_Application_Module_Bootstrap{ 
    protected function _initAutoload(){ 
        $autoloader = new Zend_Application_Module_Autoloader(array( 
                    'namespace' => '', 
                    'basePath' => dirname(__FILE__), 
                )); 
        return $autoloader; 
    } 
    
    protected function _initRoute()
    {                        
        $frontController = Zend_Controller_Front::getInstance();
        $router = $frontController->getRouter();
        
        //Set Router by Config file
//        $frontController->addControllerDirectory(APPLICATION_PATH.'/modules/default/controllers');        
//        $configRoute = new Zend_Config_Ini(CONFIG_PATH.'/route.ini','thietlap');                        
//        $router->addConfig($configRoute,'routes');        
//        $frontController->setRouter($router);
        
        
        $indexRoute = new Zend_Controller_Router_Route_Static('rao-vat',
            array('controller' => 'index', 'module' => 'default', 'action' => 'index'));
                    
        $indexPageRoute = new Zend_Controller_Router_Route_Regex('rao-vat/(\d+)/(.*)/(\d+)/(.*)/(.*)/(\d+)/p(\d+)',
            array(                
                'controller'    => 'index',
                'module'        => 'default',
                'action'        => 'index',                                                                              
            ),       
            array(
                1 => 'catId',
                2 => 'itemId',  
                3 => 'areaId',
                4 => 'title',
                5 => 'transaction',
                6 => 'view',
                7 => 'page'
            ),
            'rao-vat/%d/%s/%d/%s/%s/%d/p%d'
        );
        $router->addRoute('index.pagination',$indexPageRoute);    
                            
        $loginRoute = new Zend_Controller_Router_Route_Static('dang-nhap',
            array('controller' => 'auth', 'module' => 'default', 'action' => 'login'));        
        $logoutRoute = new Zend_Controller_Router_Route_Static('dang-xuat',
            array('controller' => 'auth', 'module' => 'default', 'action' => 'logout'));
        $regisRoute = new Zend_Controller_Router_Route_Static('dang-ky',
            array('controller' => 'auth', 'module' => 'default', 'action' => 'regis'));
                                    
        $userIndexRoute = new Zend_Controller_Router_Route_Static('quan-ly-tai-khoan',
            array('controller' => 'user', 'module' => 'default', 'action' => 'index'));                    
        $userRechargeRoute = new Zend_Controller_Router_Route_Static('nap-tien',
            array('controller' => 'user', 'module' => 'default', 'action' => 'recharge'));
        $userPromanRoute = new Zend_Controller_Router_Route_Static('quan-ly-tin',
            array('controller' => 'user', 'module' => 'default', 'action' => 'proman'));
        $userForgotpassRoute = new Zend_Controller_Router_Route_Static('quen-mat-khau',
            array('controller' => 'user', 'module' => 'default', 'action' => 'forgotpass'));
                                                        
        $productPostRoute = new Zend_Controller_Router_Route_Static('dang-tin-thuong',
            array('controller' => 'product', 'module' => 'default', 'action' => 'post'));            
        $productPostvipRoute = new Zend_Controller_Router_Route_Static('dang-tin-vip',
            array('controller' => 'product', 'module' => 'default', 'action' => 'postvip'));
        $productResultRoute = new Zend_Controller_Router_Route_Static('dang-tin-rao-vat',
            array('controller' => 'product', 'module' => 'default', 'action' => 'result'));
            
        $productReviewRoute = new Zend_Controller_Router_Route_Regex('kiem-tra-lai/re(\d+)-(.*)',
            array(                
                'controller'    => 'product',
                'module'        => 'default',
                'action'        => 'review',
            ),       
            array(
                1 => 'id',
                2 => 'title'
            ),  
            'kiem-tra-lai/re%d-%s'
        );
        $router->addRoute('product.review',$productReviewRoute);            
            
        $productEditPostRoute = new Zend_Controller_Router_Route_Regex('dang-tin-thuong/ed(\d+)-(.*)',
            array(                
                'controller'    => 'product',
                'module'        => 'default',
                'action'        => 'post',
            ),       
            array(
                1 => 'id',
                2 => 'title'
            ),  
            'dang-tin-thuong/ed%d-%s'
        );
        $router->addRoute('product.editpost',$productEditPostRoute);
          
        $productEditPostvipRoute = new Zend_Controller_Router_Route_Regex('dang-tin-vip/ed(\d+)-(.*)',
            array(                
                'controller'    => 'product',
                'module'        => 'default',
                'action'        => 'postvip',
            ),       
            array(
                1 => 'id',
                2 => 'title'
            ),  
            'dang-tin-vip/ed%d-%s'
        );
        $router->addRoute('product.editpostvip',$productEditPostvipRoute);              
          
        $productReviveRoute = new Zend_Controller_Router_Route_Regex('tai-dang/p(\d+)-(.+)',
            array(                
                'controller'    => 'product',
                'module'        => 'default',
                'action'        => 'revive',
            ),       
            array(
                1 => 'id',
                2 => 'title'
            ),  
            'tai-dang/p%d-%s'
        );
        $router->addRoute('product.revive', $productReviveRoute);
            
        $productTopRoute = new Zend_Controller_Router_Route_Regex('lam-moi/p(\d+)-(.+)',
            array(
                'controller'    => 'product',
                'module'        => 'default',
                'action'        => 'top',
            ),
            array(
                1 => 'id',
                2 => 'title'
            ),
            'lam-moi/p%d-%s'
        );
        $router->addRoute('product.top', $productTopRoute);
        
        $productDeleteRoute = new Zend_Controller_Router_Route_Regex('xoa-tin/p(\d+)-(.+)',
            array(
                'controller'    => 'product',
                'module'        => 'default',
                'action'        => 'delete',
            ),
            array(
                1 => 'id',
                2 => 'title'
            ),
            'xoa-tin/p%d-%s'
        );
        $router->addRoute('product.delete', $productDeleteRoute);
        
        $productDetailRoute = new Zend_Controller_Router_Route_Regex('chi-tiet/p(\d+)-(.+)',
            array(
                'controller'    => 'product',
                'module'        => 'default',
                'action'        => 'detail',
            ),
            array(
                1 => 'id',
                2 => 'title'
            ),
            'chi-tiet/p%d-%s'
        );
        $router->addRoute('product.detail', $productDetailRoute);
        
        $productCatRoute = new Zend_Controller_Router_Route_Regex('fa(\d+)-(.+)',
            array(
                'controller'    => 'index',
                'module'        => 'default',
                'action'        => 'index',
            ),
            array(
                1 => 'catId',
                2 => 'shortName'
            ),
            'fa%d-%s'
        );
        $router->addRoute('index.faId', $productCatRoute);
                
        $productItemtRoute = new Zend_Controller_Router_Route_Regex('(.+)/so(\d+)-(.+)',
            array(
                'controller'    => 'index',
                'module'        => 'default',
                'action'        => 'index',
            ),
            array(
                1 => 'catName',
                2 => 'itemId',
                3 => 'shortName',
            ),
            '%s/so%d-%s'
        );
        $router->addRoute('index.soId', $productItemtRoute);
        
        $router->addRoute('index.index',$indexRoute);
        $router->addRoute('auth.login',$loginRoute);
        $router->addRoute('auth.logout',$logoutRoute);
        $router->addRoute('auth.regis',$regisRoute);
        
        $router->addRoute('user.index',$userIndexRoute);
        $router->addRoute('user.recharge',$userRechargeRoute);
        $router->addRoute('user.proman',$userPromanRoute);
        $router->addRoute('user.forgotpass',$userForgotpassRoute);
        
        $router->addRoute('product.post',$productPostRoute);
        $router->addRoute('product.postvip',$productPostvipRoute);
        $router->addRoute('product.result',$productResultRoute);
        //pr($router);
    }

}